<template>
	<view class="page">
		<mallHeader title="收支明细"></mallHeader>
		<view class="list pad" v-if="list.length > 0">
			<navigator :url="'./incomeDtl?id=' + JSON.stringify(a)" hover-class="none" class="item" v-for="(a,i) in list">
				<view class="item1">
					<view class="left">{{ a.describe }}</view>
					<view class="right" :class="{add:i>2}">
						-{{ a.money }}
					</view>
				</view>
				<view class="item2">
					<view class="left">{{ a.create_time }}</view>
					<view class="right" :class="{add:i>2}">
						(CD ￥)
					</view>
				</view>
			</navigator>
		</view>
		
		<view class="empty" v-if="empty">
			<img src="/static/images/public/no-bill.png" alt="">
			您还没有账单记录哦，快去前往消费
		</view>
	</view>
</template>

<script>
	import mallHeader from '@/components/mallHeader/mallHeader';
	import page from '@/common/jsMixin/page';
	import {payList, isLogin} from '@/api/substitution.js'
	
	
	export default {
		mixins:{page},
		components:{
			mallHeader
		},
		data(){
			return {
				page:1,
				list:[],
				ruleForm: {
					page: 1
				},
				total: '',
				empty: false,
			}
		},
		onLoad() {
			// 页面加载中
			uni.showLoading({
				mask: true
			});
			
			isLogin()
			
			this.getData();
		},
		
		// 下拉刷新
		onPullDownRefresh() {
			this.ruleForm.page = 1;
			this.getData()
		},
		
		// 上拉加载
		onReachBottom() {
			if (this.ruleForm.page < this.total) {
				this.ruleForm.page += 1;
				this.getData()
			}
		},
		
		methods:{
			
			// 数据
			getData(){
				payList(this.ruleForm).then(res => {
					if (this.ruleForm.page === 1) {
						this.list = res.data.list.data;
						this.total = res.data.list.last_page;
						if (this.list.length === 0) {
							this.empty = true
						}
					} else {
						res.data.list.data.forEach(item => {
							this.list.push(item)
						})
					}
					uni.stopPullDownRefresh()
				})
			}
			
		},
	}
</script>

<style lang="scss" scoped>
	.list{
		background-color: #FFFFFF;
		margin-top: 20px;
	}
	.item{
		// border-radius: 20rpx;
		padding: 30rpx 0;
		&:not(:last-child){
			border-bottom:1px solid #CDCDCD;
		}
		.right.add{
			color: #FE7B47;
		}
		.item1{
			display: flex;
			justify-content: space-between;
			font-size: 32rpx;
			color: #333333;
			font-weight: 550;
			.left{
				text-overflow: ellipsis;
				overflow: hidden;
				white-space: nowrap;
				width: 450rpx;
			}
		}
		.item2{
			display: flex;
			justify-content: space-between;
			font-size: 26rpx;
			margin-top: 10rpx;
		}
	}
	
	
	.empty {
			min-height: 900rpx;
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;
			font-size: 30rpx;
			color: #333;
				
			img {
				width: 300rpx;
				margin-bottom: 30rpx;
			}
		}
</style>
